/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.GoicocheaProblem;
import Simplex.Simplex;

/**
 *
 * @author Stiv
 */
public class GoicocheaController {
    
    private Simplex simplex;
    private GoicocheaProblem goico;
    
    public void equivalence(double matriz[][]) {
        int size = matriz.length;
        for (int i = 0; i < size; i++) {
            for (int j = 0; j < size; j++) {
                if (matriz[i][j] < 0) {
                    matriz[i][j] = matriz[i][j] * (-1);
                }
            }
        }
    }

    public void applySimplex(double objectives[][], double[][] restrictionsA, double[] restrictionsB, GoicocheaProblem goicoch) {
        int numVar = goicoch.getNumVar();
        double result[] = new double[numVar];
        double results[][] = new double[numVar][numVar];
        //Se aplica el método Simplex a cada una de las filas de la matriz de objetivos.    
        double c[] = new double[numVar];
        for (int i = 0; i < numVar; i++) {
            for (int j = 0; j < numVar; j++) {
                c[j] = objectives[i][j];
            }
            simplex = new Simplex(restrictionsA, restrictionsB, c);
            result=simplex.primal();
            for (int j = 0; j < numVar; j++){
                results[i][j]=result[j];
                goicoch.setResult(results);
            }
        }
    }
    
    // (Paso 4)Encontrar los Zmaximos al reemplazar el resultado del simplex en la funcion objetivo.
    public static void Zmaxim(GoicocheaProblem G){
        double Z[][]= G.getObjectives(); //Funciones objetivo
        double result[][] = G.getResult(); // resultados del simplex
        double Zmax[] = new double[G.getNumVar()];
        for(int i=0;i<Z.length;i++){
            double Sum = 0.0;
            for(int j=0;j<Z.length;j++){
                Sum = Sum + Z[i][j]*result[i][j];
                
                
            }
            Zmax[i]=Sum;
            System.out.println(Sum);
            
        }
        G.setZMax(Zmax);
        
        
        
    }
}
